package spring.cloud.service.task.service;

import com.alibaba.fastjson2.JSONObject;
import spring.cloud.service.task.domain.executor.Executor;
import spring.cloud.service.task.domain.task_executor.TaskExecutor;
import spring.cloud.service.task.domain.task_executor.TaskExecutorStatusInfo;
import spring.cloud.service.task.domain.task_item.TaskItemExecuteInfo;
import spring.cloud.service.task.dto.TaskDto;
import spring.cloud.service.task.utils.PageInfo;
import spring.cloud.service.task.utils.Result;

import java.util.List;

public interface TaskService {
    PageInfo getTaskList(String namespaceKey, String description, String status, Integer page, Integer limit);

    Result addTask(TaskDto taskDto);

    Result updateTask(TaskDto taskDto);

    Result deleteTask(TaskDto taskDto) throws RuntimeException;

    Result enableTask(String nameSpace, String taskId, String userId) throws RuntimeException;

    Result disableTask(String nameSpace, String taskId, String userId) throws RuntimeException;

    Result stopTaskInstanceId(String nameSpace, String taskId, String taskInstanceId, final JSONObject triggeredData) throws RuntimeException;

    Result rerunTaskInstanceId(String nameSpace, String taskId, String taskInstanceId, final JSONObject triggeredData) throws RuntimeException;

    Result runTaskInstanceId(String nameSpace, String taskId, final JSONObject triggeredData) throws RuntimeException;


    /**
     * 获取该任务可选择的优先Executor
     */
    List<Executor> getExecutorList(String nameSpace, String taskId) throws RuntimeException;

    void setPreferExecutorIdList(String nameSpace, String taskId, String preferExecutorIdList) throws RuntimeException;


    List<TaskDto> getTaskDtoList(String nameSpace) throws RuntimeException;


    List<String> getTaskIdList(String nameSpace) throws RuntimeException;


    TaskDto getTaskConfiguration(String nameSpace, String taskId) throws RuntimeException;


    List<String> getExecutorIdList(String nameSpace, String taskId) throws RuntimeException;


    List<String> getTaskIdListFromZooKeeper(String nameSpace) throws RuntimeException;


    /**
     * 获取任务所分配的executor及先关分配信息。
     */
    List<TaskExecutor> getTaskExecutorList(String nameSpace, String taskId) throws RuntimeException;

    /**
     * 获取JobServer状态信息
     */
    List<TaskExecutorStatusInfo> getTaskExecutorStatusInfoList(String nameSpace, String taskId) throws RuntimeException;


    /**
     * 获取任务运行状态
     */
    List<TaskItemExecuteInfo> getTaskItemExecuteInfoList(String nameSpace, String taskId) throws Exception;


    /**
     * Get the job info by nameSpace and taskId pair.
     *
     * @throws RuntimeException for below scenarios: <ul> <li>nameSpace or taskId is not found (statusCode =
     *                          404)</li> <li>Other exceptions (statusCode = 500)</li> </ul>
     */
    TaskDto getTaskInfo(String nameSpace, String taskId) throws RuntimeException;

    /**
     * Get the jobs info under the nameSpace
     */
    List<TaskDto> getTaskInfoList(String nameSpace) throws RuntimeException;


}
